local blaze = require "blaze"
local gamelib = require "club.threecard.gamelib"
local slotlib = require "club.threecard.slotlib"
local game = require "club.threecard.royalchina"

local Matcher = gamelib.entitas.Matcher
local components = slotlib.components

local M = game.ui.activity()

M.store_watchers = {
    machine = {
        ["$"] = blaze.noop,

        ["旋转结果"] = function(self, store, state, args)
            local c = self.context:get_unique_component(components.result_info_component)
            c.info = args
        end
    }
}

function M:ctor()
    self.res = "club.threecard.royalchina/ui/gamescene.b:gamescene"
    self.machine = slotlib.machine.create(game.config.machine)
    self.context = game.entitas.Context.new()
    self.systems = game.entitas.CoroutineSystems.new()

    local systems = game.require "gameui.gamescene.systems"
    for _, system in ipairs(systems) do
        self.systems:add(system.new(self.context, self))
    end

    self.hud = slotlib.require("widget.Hud").new(self)
    self.jackpot = slotlib.require("widget.Jackpot").new()
end

function M:on_load()
    self:super("on_load")
    self.machine:load(self.content)
    self.hud:load()
    self.hud:set_parent(self.hud_root, false)
    self.jackpot:load()
    self.jackpot:set_parent(self.jackpot_root, false)
    self.systems:initialize()
end

function M:on_injected(bind)
    bind("button.click", self.btn_help, self.help_ivk)

    game.utility.button_style.highlight_scale(self.btn_help)
end

function M:help_ivk()
    game.toast.show("加油~")
end

return M